package com.oldroid.apps.getit.ui.adapter;

import java.util.List;

import com.oldroid.apps.getit.R;
import com.oldroid.apps.getit.util.Shortcut;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ShortcutAdapter extends ArrayAdapter<Shortcut> {

	private Context mContext;
	private Shortcut[] list;
	private boolean isShortcut;

	public ShortcutAdapter(Context context, int textViewResourceId,
			Shortcut[] list, boolean isShortcut) {
		super(context, textViewResourceId, list);
		mContext = context;
		this.list = list;
		this.isShortcut = isShortcut;
	}

	static class ViewHolder {
		public ImageView imageView;
		public TextView textView;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = (LayoutInflater) mContext
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.shortcut_row, null, true);
			holder = new ViewHolder();
			holder.imageView = (ImageView) rowView
					.findViewById(R.id.shortcut_icon);
			holder.textView = (TextView) rowView
					.findViewById(R.id.shortcut_text);
			rowView.setTag(holder);
		} else {
			holder = (ViewHolder) rowView.getTag();
		}

		holder.textView.setText(list[position].getName());
		if (isShortcut) {
			switch (position) {
			case 0:
				holder.imageView.setImageResource(R.drawable.shortcut_home);
				break;
			case 1:
				holder.imageView
						.setImageResource(R.drawable.shortcut_downloads);
				break;
			default:
			}
		}
		return rowView;
	}

}
